package com.example.f8399.testdemo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.example.f8399.testdemo.R;
import com.example.f8399.testdemo.bean.ItemLvOne;
import com.example.f8399.testdemo.bean.ItemLvTwo;

import java.util.List;

/**
 * Created by lcfeng on 2018/12/3/003
 * Describe:
 */
public class ExpandListAdapter2 extends BaseMultiItemQuickAdapter<MultiItemEntity,BaseViewHolder> {
    public static final int TYPE_1 = 1;
    public static final int TYPE_2 = 2;
    private Context mContext;
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ExpandListAdapter2(Context context,List<MultiItemEntity> data) {
        super(data);
        mContext = context;
        addItemType(TYPE_1, R.layout.item_expand_lev1);
        addItemType(TYPE_2, R.layout.item_expand_lev2);
    }


    @Override
    protected void convert(final BaseViewHolder helper, final MultiItemEntity item) {
        switch (helper.getItemViewType()) {
            case TYPE_1:
                final ItemLvOne item1 = (ItemLvOne) item;
                helper.setText(R.id.tv_title, item1.getTitle());
                RequestOptions options = new RequestOptions().placeholder(R.mipmap.ic_launcher);
                Glide.with(mContext).load("http://qiniu.shenbiantao.net/FsD7uvTeKwKAqrNjWkXdVmYJBVKp").apply(options).into((ImageView) helper.getView(R.id.iv_action));
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (item1.isExpanded()) {
                            collapse(helper.getLayoutPosition());
                        }else {
                            expand(helper.getLayoutPosition());
                        }

                    }
                });
                break;
            case TYPE_2:
                ItemLvTwo item2 = (ItemLvTwo) item;
                helper.setText(R.id.tv_msg, item2.getName());
                break;
        }
    }
}
